package cn.hzc.fortess.system.service;

import cn.hzc.fortess.system.dao.LogDao;
import cn.hzc.fortess.system.entity.BizLog;
import cn.hzc.fortess.system.page.Pagination;
import cn.hzc.fortess.system.search.BizLogSearch;
import cn.hzc.fortess.system.search.LoginLogSearch;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class LogServiceImpl implements LogService {


    @Autowired
    LogDao logDao;

    @Override
    public Pagination getLoginLogPage(LoginLogSearch search) {
        Pagination pagination = new Pagination();
        pagination.setCount(logDao.countLoginLog(search));
        if (pagination.getCount() > 0) {
            pagination.setData(logDao.pageLoginLog(search));
        }
        return pagination;
    }

    @Override
    public Pagination getBizLogPage(BizLogSearch search) {
        Pagination pagination = new Pagination();
        pagination.setCount(logDao.countBizLog(search));
        if (pagination.getCount() > 0) {
            pagination.setData(logDao.pageBizLog(search));
        }
        return pagination;
    }

    @Override
    @Transactional
    public void deleteBizLog(String[] ids) {
        for(String id:ids){
            if(StringUtils.isBlank(id)){
                continue;
            }
            logDao.deleteBizLog(Long.parseLong(id));
        }
    }

    @Override
    public BizLog getBizLogById(Long id) {
        return logDao.findBizLogById(id);
    }
}
